package base.java.security;

import java.util.LinkedHashMap;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.security.ConfigAttribute;
import org.springframework.security.ConfigAttributeDefinition;
import org.springframework.security.SecurityConfig;
import org.springframework.security.intercept.web.RequestKey;

public class RequestMapFactoryBean implements FactoryBean
{
	private LinkedHashMap<RequestKey, ConfigAttributeDefinition> requestMap;

	public void init()
	{
		requestMap = new LinkedHashMap<RequestKey, ConfigAttributeDefinition>();
		RequestKey key = new RequestKey("/**");
		ConfigAttribute attribute = new SecurityConfig("ROLE_XXX");
		ConfigAttributeDefinition definition = new ConfigAttributeDefinition(attribute);
		requestMap.put(key, definition);

		key = new RequestKey("/hai.jsp");
		attribute = new SecurityConfig("ROLE_EEE");
		definition = new ConfigAttributeDefinition(attribute);
		requestMap.put(key, definition);
	}

	public Object getObject() throws Exception
	{
		if (requestMap == null)
		{
			init();
		}
		return requestMap;
	}

	public Class getObjectType()
	{
		return LinkedHashMap.class;
	}

	public boolean isSingleton()
	{
		return true;
	}

}
